//
//  AllH5ShownViewController.m
//  NiuBanGold
//
//  Created by Billy on 15/12/8.
//  Copyright © 2015年 zzjr. All rights reserved.
//

#import "AllH5ShownViewController.h"

@interface AllH5ShownViewController ()<UIWebViewDelegate>

@property (nonatomic, strong)UIWebView *view_webView; //展示的view
@property (nonatomic, strong)MBProgressHUD *hud;

@end

@implementation AllH5ShownViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self pageSettingsAndSubviewsCreation];
}

#pragma mark - SubviewsCreationAndPageSettings

- (void) pageSettingsAndSubviewsCreation {
    
    [self.view setBackgroundColor:[UIColor whiteColor]];

    [self.navigationItem setTitle:(self.str_title?self.str_title:@"活动详情")];
    
    [self.view addSubview:self.view_webView];
    
    [self loadPageData]; //加载网页

}

- (void) loadPageData {

    [self.view_webView.scrollView.mj_header endRefreshing];
    
    if (self.str_url) {
        
        [self.hud show:YES];
        
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.str_url]];
        
        [self.view_webView loadRequest:request];
    }
}


#pragma mark - Webview delegate

-(void)webViewDidFinishLoad:(UIWebView *)webView {
    
    [self.hud hide:YES];
}

#pragma mark - setter methods

- (UIWebView *)view_webView {
    
    if (!_view_webView) {
        
        _view_webView =  [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - MULTIPLYHEIGHT(64.0))];
        [_view_webView setDelegate:self];
        [_view_webView setScalesPageToFit:YES];
        
        _view_webView.scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            // 进入刷新状态后会自动调用这个block
            
            [self loadPageData];
        }];
    }
    
    return _view_webView;
}

- (MBProgressHUD *)hud {
    
    if (!_hud) {
        
        _hud = [MBProgressHUD showHUDAddedTo:self.view_webView animated:YES];
        [_hud setLabelText:@"正在加载..."];
    }
    
    return _hud;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
